package mortal.game.control
{
    import Message.Db.Tables.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import fl.data.*;
    import flash.events.*;
    import flash.utils.*;
    import modules.*;
    import mortal.game.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.scene.ai.*;
    import mortal.game.scene.events.*;
    import mortal.game.scene.layer.utils.*;
    import mortal.game.scene.player.entity.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.copy.defin.*;
    import mortal.game.view.copy.entrance.*;
    import mortal.game.view.copy.popupBox.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class CopyController extends Controller
    {
        private var _entrance:CopyEntrenceModule;
        private var _copyGroup:CopyGroupModule;
        private var _ApplyHint:CopyPlayerApply;
        private var _playerListModule:CopyPlayerListModule;
        private var _copyConfirmPanel:CopyConfirmPanel;
        private var _isViewGroup:Boolean = false;
        private var _copyHintIcon:CopyHintIcon;
        private var _copyPlayerList:CopyPlayerListModule;
        private var _minimizeItem:CopyMinimize;
        private var _countDownLabel:CopyCountDownLabel;
        private var _isInCopy:Boolean = false;
        private var _isInGroup:Boolean = false;
        private var _roomSetData:RoomSetData;
        private var _openRoomHintTimer:Timer;
        private var _copyGroupModule:CopyGroupModuleNew;

        public function CopyController()
        {
            ClockManager.instance.addEventListener(TimeEvent.DateChange, this.onCleanCopyEnteredNum);
            
        }

        public function get copyGroupModule() : CopyGroupModuleNew
        {
            if (!this._copyGroupModule)
            {
                this._copyGroupModule = new CopyGroupModuleNew();
                this._copyGroupModule.addEventListener(Event.ADDED_TO_STAGE, this.onCopyGroupAddedToStage);
                this._copyGroupModule.addEventListener(CopyGroupModuleNew.Event_DoEnterCopy, this.onCopyGroupEnterCopy);
                Dispatcher.addEventListener(EventName.CopyGroupRefreshNearby, this.doRefreshNearbyList);
                NetDispatcher.addCmdListener(ServerCommand.Group_PlayerInfoChange, this.onGroupMemberInfoChange);
                NetDispatcher.addCmdListener(ServerCommand.Group_CaptainChange, this.onGroupMemberInfoChange);
            }
            return this._copyGroupModule;
        }

        public function get hintIcon() : CopyHintIcon
        {
            if (!this._copyHintIcon)
            {
                this._copyHintIcon = new CopyHintIcon();
                this._copyHintIcon.addEventListener(CopyHintIcon.CopyHintIconClick, this.onHintIconClick);
            }
            return this._copyHintIcon;
        }

        public function get playerListWin() : CopyPlayerListModule
        {
            if (!this._copyPlayerList)
            {
                this._copyPlayerList = new CopyPlayerListModule();
            }
            return this._copyPlayerList;
        }

        public function get copyConfirmPanel() : CopyConfirmPanel
        {
            if (!this._copyConfirmPanel)
            {
                this._copyConfirmPanel = new CopyConfirmPanel();
                this._copyConfirmPanel.addEventListener(CopyConfirmPanel.MINIMIZE, this.onConfirmPanelButtonClick);
                this._copyConfirmPanel.addEventListener(CopyConfirmPanel.CANCEL, this.onConfirmPanelButtonClick);
                this._copyConfirmPanel.addEventListener(CopyConfirmPanel.OK, this.onConfirmPanelButtonClick);
            }
            return this._copyConfirmPanel;
        }

        public function get copyGroup() : CopyGroupModule
        {
            return this._copyGroup;
        }

        override protected function initView() : IView
        {
            if (!this._entrance)
            {
                this._entrance = new CopyEntrenceModule();
                this._entrance.addEventListener(Event.ADDED_TO_STAGE, this.onAddToStage);
            }
            return this._entrance;
        }

        override protected function initServer() : void
        {
            Dispatcher.addEventListener(EventName.CopyFindPlayer, this.FindPlayerHandler);
            Dispatcher.addEventListener(EventName.CopyInvitePlayer, this.InvitePlayerHandler);
            Dispatcher.addEventListener(EventName.CopyRefreshGroup, this.doRefreshRoomList);
            Dispatcher.addEventListener(EventName.CopyRoomSet, this.roomSetHandler);
            Dispatcher.addEventListener(EventName.CopyCreateGroup, this.doCreateGroup);
            Dispatcher.addEventListener(EventName.CopyQuitHell, this.onQuitHell);
            Dispatcher.addEventListener(EventName.CopyQuitCopy, this.onQuitCopy);
            Dispatcher.addEventListener(EventName.CopyMinimize, this.onMinimize);
            Dispatcher.addEventListener(EventName.CopyJoinGroup, this.doJoin);
            Dispatcher.addEventListener(EventName.CopyOpenCopy, this.doOpenCopy);
            Dispatcher.addEventListener(EventName.CopyKickOut, this.doKickOut);
            Dispatcher.addEventListener(EventName.CopyLeave, this.doLeave);
            Dispatcher.addEventListener(EventName.CopyLeaveWithoutComfirm, this.doLeaveWithoutComfirm);
            Dispatcher.addEventListener(EventName.CopyOpenInviteWin, this.doOpenInviteWin);
            Dispatcher.addEventListener(EventName.CopyAgreeInvite, this.doAgreeInvite);
            Dispatcher.addEventListener(EventName.CopyRejectInvite, this.doRejectInvite);
            Dispatcher.addEventListener(EventName.CopyViewGroup, this.doViewGroup);
            Dispatcher.addEventListener(EventName.CopyAgreeApply, this.doAgreeApply);
            Dispatcher.addEventListener(EventName.CopyRejectApply, this.doRejectApply);
            Dispatcher.addEventListener(EventName.CopyCaptainViewGroup, this.doCaptainViewGroup);
            Dispatcher.addEventListener(EventName.CopyUpdateRoomSetting, this.updateRoomSettingWin);
            Dispatcher.addEventListener(EventName.CopyCopyChooseFromNpc, this.onCopyChooseFromNpc);
            NetDispatcher.addCmdListener(ServerCommand.Copy_CloseHell, this.onCloseHell);
            NetDispatcher.addCmdListener(ServerCommand.Copy_CopyNumInfoChange, this.onCopyNumInfoChange);
            NetDispatcher.addCmdListener(ServerCommand.Copy_RefreshCountDownInfo, this.onCountDownInfoChange);
            NetDispatcher.addCmdListener(ServerCommand.Copy_CreateCopy, this.onCreateCopy);
            NetDispatcher.addCmdListener(ServerCommand.Copy_EnterCopy, this.onEnterCopy);
            NetDispatcher.addCmdListener(ServerCommand.Copy_WaitingInfoCommand, this.onUpdateWaitingInfo);
            RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onCopyNumInfoChange);
            
        }

        override public function get view() : IView
        {
            if (_view == null)
            {
                _view = this.initView();
            }
            return _view;
        }

        public function get applyHint() : CopyPlayerApply
        {
            if (!this._ApplyHint)
            {
                this._ApplyHint = new CopyPlayerApply();
            }
            return this._ApplyHint;
        }

        public function stageResize() : void
        {
            if (this._minimizeItem)
            {
                this._minimizeItem.moveTo(Global.stage.stageWidth - 290, 140);
            }
            if (this._countDownLabel)
            {
                this._countDownLabel.x = Global.stage.stageWidth - 450;
                this._countDownLabel.y = 60;
            }
            
        }

        private function onEnterHell(param1:Object) : void
        {
            cache.copy.isInHell = true;
            _view = this._copyGroup;
            if (this._entrance)
            {
                this._entrance.hide();
            }
            if (cache.copy.copyInfo)
            {
                if (this._copyGroup && cache.copy.copyInfo.singleMode != 1)
                {
                    MsgManager.addBroadCast("你已自动加入该副本报名列表，退出界面报名消息将会自动清除");
                    this._copyGroup.show();
                }
            }
            
        }

        private function onAddToStage(event:Event) : void
        {
            this.updateCopyList();
            
        }

        private function onOpenGroupUI(event:Event) : void
        {
            var _loc_2:TCopy = null;
            if (this._minimizeItem)
            {
                this._minimizeItem.hide();
            }
            if (!cache.copy.copyInfo && cache.copy.groupInfo)
            {
                _loc_2 = CopyConfig.instance.getInfoByCode(1);
                cache.copy.copyInfo = _loc_2;
            }
            this._copyGroup.updateCopyInfo(cache.copy.copyInfo);
            if (cache.copy.groupInfo)
            {
                this.onGroupInfoChange();
                this.onPlayerInfoChange();
            }
            
        }

        private function onCleanCopyEnteredNum(param1:Object = null) : void
        {
            cache.copy.cleanCopyEnteredNum();
            this.onCopyNumInfoChange();
            var _loc_2:* = new Date();
            _loc_2.setHours(23, 59, 59, 999);
            ClockManager.instance.setNowTimer(_loc_2.getTime() - 10 * 1000);
            
        }

        private function onCloseHell(param1:Object) : void
        {
            cache.copy.isInHell = false;
            if (this._entrance && this._copyGroup)
            {
                _view = this._entrance;
                this._copyGroup.close();
                if (this._minimizeItem)
                {
                    this._minimizeItem.hide();
                }
            }
            if (this._countDownLabel)
            {
                this._countDownLabel.hide();
                this._countDownLabel = null;
            }
            
        }

        private function onInvite(param1:Object = null) : void
        {
            if (cache.copy.inviteList.length > 0)
            {
                this.hintIcon.show();
                this.updateInviteData();
            }
            
        }

        private function onApply(param1:Object = null) : void
        {
            var _loc_2:* = cache.copy.applyList[0] as SGroupInvite;
            if (_loc_2)
            {
                this.applyHint.applyData = _loc_2;
                this.applyHint.show();
            }
            
        }

        private function onRoomListInfoChange(param1:Object) : void
        {
            this._copyGroup.updateRoomList(cache.copy.groups, cache.copy.groupCounts);
            
        }

        private function onGroupInfoChange(param1:Object = null) : void
        {
            this._copyGroup.updateGroupInfo(cache.copy.groupInfo, cache.copy.isInGroup, EntityUtil.toString(cache.copy.groupInfo.captainId) == EntityUtil.toString(cache.role.entityInfo.entityId));
            this.checkInCopy();
            
        }

        private function checkInCopy() : void
        {
            var _loc_1:* = cache.copy.isInCopy;
            var _loc_2:* = cache.copy.isInGroup;
            if (_loc_2)
            {
                if (this._copyHintIcon)
                {
                    this._copyHintIcon.hide();
                }
            }
            if (this._isInGroup != _loc_2)
            {
                this._isInGroup = _loc_2;
                if (this._copyGroup)
                {
                    this._copyGroup.reGetList();
                }
            }
            if (this._isInCopy != _loc_1)
            {
                this._isInCopy = _loc_1;
                if (this._isInCopy)
                {
                    this.onMinimize();
                    this.updateMinimizeInfo();
                    if (this._copyGroup)
                    {
                        this._copyGroup.hide();
                    }
                }
            }
            
        }

        private function onMinimize(event:DataEvent = null) : void
        {
            
        }

        private function onQuitHell(event:DataEvent) : void
        {
            var _loc_2:String = null;
            if (_view)
            {
                _view.hide();
            }
            if (cache.guide.copyStudy)
            {
                GameProxy.copy.leftGroup_async();
                cache.copy.isInHell = false;
            }
            else if (cache.copy.groupInfo)
            {
                if (cache.copy.isFighting && cache.copy.isInGroup)
                {
                    if (cache.copy.copyInfo && cache.copy.copyInfo.singleMode == 1)
                    {
                        _loc_2 = "是否离开当前副本？";
                    }
                    else
                    {
                        _loc_2 = "战斗中离开队伍，将会被强制\r传送出副本，是否继续？";
                    }
                    Alert.show(_loc_2, null, Alert.YES | Alert.NO, null, this.onLeaveComfirm);
                }
                else
                {
                    if (cache.copy.isInGroup)
                    {
                        GameProxy.copy.leftGroup_async();
                    }
                    _view = this._entrance;
                    cache.copy.groupInfo = null;
                    cache.copy.players = [];
                    if (this._copyGroup.showStatus == CopyGroupModule.Status_FromEntrance)
                    {
                        _view.show();
                    }
                    GameProxy.copy.leftHell_async();
                    cache.copy.isInHell = false;
                }
            }
            else
            {
                _view = this._entrance;
                if (this._copyGroup && this._copyGroup.showStatus == CopyGroupModule.Status_FromEntrance)
                {
                    _view.show();
                }
                GameProxy.copy.leftHell_async();
                cache.copy.isInHell = false;
            }
            
        }

        private function onQuitCopy(event:DataEvent) : void
        {
            var _loc_2:String = null;
            var _loc_3:uint = 0;
            if (_view)
            {
                _view.hide();
            }
            if (cache.copy.copyInfo && cache.copy.copyInfo.code == 104)
            {
                this.onLeaveComfirm(Alert.YES);
                
            }
            if (cache.copy.copyInfo && cache.copy.copyInfo.singleMode == 1 && cache.copy.copyInfo.code != 107)
            {
                if (cache.copy.getHasEnterNumById(cache.copy.copyInfo.code) >= cache.copy.copyInfo.numByDay)
                {
                    _loc_2 = "是否离开[" + cache.copy.copyInfo.name + "]副本？";
                    _loc_3 = Alert.YES;
                }
                else
                {
                    _loc_2 = "是否要再次征战[" + cache.copy.copyInfo.name + "]副本？";
                    _loc_3 = Alert.YES | Alert.NO;
                }
                Alert.yesLabel = "离开副本";
                Alert.noLabel = "再来一次";
                Alert.showCloseBtn = true;
                Alert.buttonWidth = 75;
                Alert.show(_loc_2, null, _loc_3, null, this.onLeaveComfirm);
            }
            else
            {
                _loc_2 = "确定要离开副本吗？";
                Alert.show(_loc_2, null, Alert.YES | Alert.NO, null, this.onLeaveComfirm);
            }
            
        }

        public function onLeaveComfirm(param1:int) : void
        {
            if (cache.copy.copyInfo && cache.copy.copyInfo.singleMode == 1 && cache.copy.copyInfo.code != 107)
            {
                if (param1 == Alert.NO)
                {
                    this.reset();
                }
                else if (param1 == Alert.YES)
                {
                    this.leave();
                }
            }
            else if (param1 == Alert.YES)
            {
                this.leave();
            }
            
        }

        private function leave() : void
        {
            GameProxy.copy.leftGroup_async();
            cache.copy.isInHell = false;
            if (this._countDownLabel)
            {
                this._countDownLabel.hide();
                this._countDownLabel = null;
            }
            
        }

        private function reset() : void
        {
            GameProxy.copy.resetCopy(cache.copy.copyInfo.code);
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyCopyReset));
            
        }

        private function onPlayerEnter(param1:Object = null) : void
        {
            if (this._minimizeItem)
            {
                this._minimizeItem.playerEnter();
            }
            
        }

        private function onPlayerLeave(param1:Object = null) : void
        {
            if (this._minimizeItem)
            {
                this._minimizeItem.playerLeave();
            }
            
        }

        private function onCopyGroupNoExist(param1:Object = null) : void
        {
            this._copyGroup.refreshRoomList();
            
        }

        private function onCreateCopy(event:DataEvent) : void
        {
            var _loc_2:* = cache.copy.lastCreateCopyInfo.value;
            if (EntityUtil.toString(cache.group.captain) != EntityUtil.toString(cache.role.entityInfo.entityId))
            {
                this.hintIcon.show();
            }
            else
            {
                this.hintIcon.hide();
            }
            
        }

        private function onEnterCopy(param1:Object) : void
        {
            var _loc_2:* = param1 as int;
            if (this._copyConfirmPanel)
            {
                this._copyConfirmPanel.hide();
            }
            if (this._copyHintIcon)
            {
                this._copyHintIcon.hide();
            }
            
        }

        private function onCountDownInfoChange(param1:SCopyMsgInfo) : void
        {
            var _loc_2:String = null;
            var _loc_3:CopyRewardsAccountPanel = null;
            if (!this._countDownLabel)
            {
                this._countDownLabel = new CopyCountDownLabel();
            }
            switch(param1.type.value())
            {
                case ECopyInfoType._ECopyInfoTypeRing:
                {
                    this._countDownLabel.setTimeLabel_Ring(param1.num1, param1.num2);
                    break;
                }
                case ECopyInfoType._ECopyInfoTypeEnd:
                {
                    this._countDownLabel.setTimeLabel_End(param1.num1);
                    break;
                }
                case ECopyInfoType._ECopyInfoTypeEvenCut:
                {
                    this._countDownLabel.setKillCountsLabel(param1.num1, param1.num2, param1.num3);
                    break;
                }
                case ECopyInfoType._ECopyInfoTypeExchange:
                {
                    _loc_2 = CopyConfig.instance.getInfoByCode(param1.num3).name;
                    _loc_3 = new CopyRewardsAccountPanel();
                    _loc_3.title = _loc_2;
                    PopupManager.addPopUp(_loc_3, "", false);
                    _loc_3.startAccounts(param1.num4, param1.num5, param1.num1, param1.num2, param1.num6);
                    break;
                }
                default:
                {
                    break;
                }
            }
            if (this._countDownLabel.isHide)
            {
                this._countDownLabel.show();
            }
            this.stageResize();
            
        }

        private function onCopyNumInfoChange(param1:Object = null) : void
        {
            var _loc_2:SPlayerCopy = null;
            var _loc_3:TCopy = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            if (this._entrance)
            {
                this._entrance.updateStatus();
            }
            if (cache.copy.copyInfo)
            {
                _loc_2 = cache.copy.getCopyNumInfoByCode(cache.copy.copyInfo.code);
                _loc_3 = cache.copy.copyInfo;
                _loc_4 = cache.copy.totalEnterNum;
                _loc_5 = 0;
                if (_loc_2)
                {
                    _loc_5 = _loc_2.todayEnterNum;
                }
                if (this._copyGroup)
                {
                    this._copyGroup.updateCopyNumInfo(_loc_5, _loc_4, _loc_5, _loc_3.numByDay);
                }
            }
            
        }

        private function onPlayerInfoChange(param1:Object = null) : void
        {
            var _loc_2:Boolean = false;
            var _loc_3:Array = null;
            var _loc_4:DataProvider = null;
            var _loc_5:Array = null;
            var _loc_6:int = 0;
            var _loc_7:SPublicMiniPlayer = null;
            var _loc_8:Boolean = false;
            var _loc_9:Boolean = false;
            if (this._copyGroup)
            {
                _loc_2 = false;
                if (cache.copy.groupInfo && EntityUtil.toString(cache.copy.groupInfo.captainId) == EntityUtil.toString(cache.role.entityInfo.entityId))
                {
                    _loc_2 = true;
                }
                _loc_3 = cache.copy.players;
                _loc_4 = new DataProvider();
                _loc_5 = [];
                _loc_6 = 0;
                while (_loc_6 < _loc_3.length)
                {
                    
                    _loc_7 = _loc_3[_loc_6] as SPublicMiniPlayer;
                    _loc_8 = EntityUtil.toString(_loc_7.entityId) == EntityUtil.toString(cache.role.entityInfo.entityId);
                    _loc_9 = cache.copy.groupInfo && EntityUtil.toString(cache.copy.groupInfo.captainId) == EntityUtil.toString(_loc_7.entityId);
                    _loc_4.addItem({type:"", online:_loc_7.online, isCaption:_loc_9, captainMode:_loc_2, isMySelf:_loc_8, data:_loc_3[_loc_6]});
                    _loc_6++;
                }
                _loc_4.sortOn(["isCaption", "online"], Array.DESCENDING);
                this._copyGroup.updateGroupInfo(cache.copy.groupInfo, cache.copy.isInGroup, _loc_2);
                this._copyGroup.updateGroupList(_loc_4);
                this._copyGroup.updateInfo();
            }
            this.updateMinimizeInfo();
            if (cache.copy.isInGroup)
            {
                cache.copy.inviteList = [];
                if (this._copyHintIcon && !this._copyHintIcon.isHide)
                {
                    this._copyHintIcon.hide();
                }
                if (cache.copy.players.length == 5 && cache.copy.isCaptain && !cache.copy.isFighting)
                {
                    this.startOpenRoomHint();
                }
                else
                {
                    this.stopOpenRoomHint();
                }
            }
            else
            {
                this.stopOpenRoomHint();
                cache.copy.applyList = [];
            }
            this.checkInCopy();
            
        }

        private function startOpenRoomHint() : void
        {
            if (!this._openRoomHintTimer)
            {
                this._openRoomHintTimer = new Timer(5000);
                this._openRoomHintTimer.addEventListener(TimerEvent.TIMER, this.doOpenRoomHint);
            }
            this._openRoomHintTimer.start();
            
        }

        private function stopOpenRoomHint() : void
        {
            if (this._openRoomHintTimer)
            {
                this._openRoomHintTimer.stop();
            }
            
        }

        private function doOpenRoomHint(event:TimerEvent) : void
        {
            MsgManager.addBroadCast("房间人数已满，请即时开启副本");
            
        }

        private function onHintIconClick(event:DataEvent) : void
        {
            this.copyConfirmPanel.updateText();
            this.copyConfirmPanel.show();
            
        }

        private function updateMinimizeInfo() : void
        {
            if (this._minimizeItem && cache.copy.copyInfo)
            {
                if (cache.copy.players.length > 0)
                {
                    this._minimizeItem.updateLabel(HTMLUtil.addColor(cache.copy.copyInfo.name, "#FBFEC9") + "(" + cache.copy.copyInfo.enterMinLevel + "级):" + cache.copy.players.length + "/5");
                }
                else
                {
                    this._minimizeItem.updateLabel(HTMLUtil.addColor(cache.copy.copyInfo.name, "#FBFEC9") + "(" + cache.copy.copyInfo.enterMinLevel + "级)");
                }
            }
            
        }

        private function roomSetHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as RoomSetData;
            this._roomSetData = _loc_2;
            cache.copy.roomSetData = _loc_2;
            if (!cache.copy.isInGroup)
            {
                GameProxy.copy.createGroup_async(_loc_2.strRoomName, _loc_2.strPassword, _loc_2.iLevelNeed, _loc_2.iPowerNeed, _loc_2.career, _loc_2.isFightOtherCanIn);
            }
            else
            {
                GameProxy.copy.modifyGroup_async(_loc_2.strRoomName, _loc_2.strPassword, _loc_2.iLevelNeed, _loc_2.iPowerNeed, _loc_2.career, _loc_2.isFightOtherCanIn);
            }
            
        }

        private function onCopyChooseFromEntrance(event:DataEvent) : void
        {
            if (Game.sceneInfo.sMapDefine.instanceType.value() == EMapInstanceType._EMapInstanceTypeGuild)
            {
                MsgManager.addBroadCast("你正在仙盟地图里面，不能进入副本！");
            }
            else if (Game.sceneInfo.sMapDefine.instanceType.value() == EMapInstanceType._EMapInstanceTypeBattlefield)
            {
                MsgManager.addBroadCast("你正在战场里面，不能进入副本！");
            }
            else
            {
                this.onCopyChoose(event);
                this._copyGroup.showStatus = CopyGroupModule.Status_FromEntrance;
            }
            
        }

        private function onCopyChoose(event:DataEvent) : void
        {
            if (!this._copyGroup)
            {
                this.initView();
            }
            this._copyGroup.showStatus = CopyGroupModule.Status_FromNpc;
            this._copyGroup.updateGroupInfo(null);
            var _loc_2:* = event.data as int;
            var _loc_3:* = CopyConfig.instance.getInfoByCode(_loc_2);
            cache.copy.copyInfo = _loc_3;
            if (_view && _view == this._copyGroup && _loc_3.singleMode != 1)
            {
                _view.show();
                
            }
            this.enterCopyHell();
            
        }

        private function onCopyChooseFromNpc(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            var _loc_3:* = CopyConfig.instance.getInfoByCode(_loc_2);
            if (!_loc_3)
            {
                MsgManager.addBroadCast("副本不存在");
                
            }
            if (!this.checkCanEnterCopy(_loc_3))
            {
                
            }
            if (_loc_3 && _loc_3.singleMode == 1)
            {
                GameProxy.copy.enterCopyEx_async(_loc_2);
            }
            else
            {
                GameProxy.copy.enterCopyWaitingRoom_async(_loc_2, true);
                this.copyGroupModule.resetCopyInfo(_loc_3);
                if (!this.copyGroupModule.isHide)
                {
                    this.copyGroupModule.hide();
                }
            }
            
        }

        private function checkCanEnterCopy(param1:TCopy) : Boolean
        {
            var info:TaskActInfo;
            var copy:* = param1;
            if (cache.role.roleInfo.level < copy.enterMinLevel)
            {
                MsgManager.addBroadCast("您的等级还不能开启此副本，赶紧提升等级吧！");
                return false;
            }
            if (cache.task.getTrasnportTask())
            {
                Alert.buttonWidth = 75;
                Alert.okLabel = "继续护送";
                Alert.show("您正在护送中，暂不能开启副本。", "提示", Alert.OK | Alert.CANCEL, null, function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    AIManager.onAutoPathAIControl(cache.task.getTrasnportTask().getTargetByIndex(0));
                }
                
            }
            );
                return false;
            }
            if (cache.copy.getCopyNumInfoByCode(copy.code) && cache.copy.getCopyNumInfoByCode(copy.code).todayEnterNum >= copy.numByDay && !Global.isDebugModle)
            {
                MsgManager.addBroadCast("次数已满");
                info = cache.task.getNearlyActiveDaily();
                if (info)
                {
                    Alert.buttonWidth = 75;
                    Alert.okLabel = "自动寻路";
                    Alert.show("副本次数已满，您现在可以完成" + HTMLUtil.addColor(info.dailyInfo.name, "#FF00FF") + "。", "提示", Alert.OK | Alert.CANCEL, null, function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.DailyActiveGoTo, info.dailyInfo));
                }
                
            }
            );
                }
                return false;
            }
            return true;
        }

        private function onCopyGroupAddedToStage(event:Event) : void
        {
            this.onGroupMemberInfoChange();
            
        }

        private function onCopyGroupEnterCopy(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            this.doEnterCopy(_loc_2);
            
        }

        private function doRefreshNearbyList(event:DataEvent) : void
        {
            this.copyGroupModule.doRefreshWaitingRoomInfo();
            
        }

        private function onGroupMemberInfoChange(param1:Object = null) : void
        {
            var _loc_7:SPublicMiniPlayer = null;
            var _loc_8:Boolean = false;
            var _loc_9:Boolean = false;
            var _loc_2:* = cache.group.isCaptain;
            var _loc_3:* = cache.group.players;
            var _loc_4:* = new DataProvider();
            var _loc_5:Array = [];
            var _loc_6:int = 0;
            while (_loc_6 < _loc_3.length)
            {
                
                _loc_7 = _loc_3[_loc_6] as SPublicMiniPlayer;
                _loc_8 = _loc_7.entityId.id == cache.role.entityInfo.entityId.id;
                _loc_9 = cache.group.captain && cache.group.captain.id == _loc_7.entityId.id;
                _loc_4.addItem({type:"", online:_loc_7.online, isCaption:_loc_9, captainMode:_loc_2, isMySelf:_loc_8, player:_loc_7});
                _loc_6++;
            }
            _loc_4.sortOn(["isCaption", "online"], Array.DESCENDING);
            this.copyGroupModule.updateGroupMemberList(_loc_4);
            
        }

        private function onUpdateWaitingInfo(param1:SCopyWaitingInfo) : void
        {
            var _loc_4:SCopyGroupInfo = null;
            var _loc_5:Array = null;
            var _loc_6:SPublicMiniPlayer = null;
            var _loc_7:int = 0;
            var _loc_2:* = CopyConfig.instance.getInfoByCode(param1.copyCode);
            if (!_loc_2)
            {
                
            }
            this.copyGroupModule.show();
            var _loc_3:Array = [];
            for each (_loc_4 in param1.groupInfos)
            {
                
                if (_loc_4.playerNum != 5)
                {
                    _loc_3.push({group:_loc_4, copy:_loc_2});
                }
            }
            _loc_5 = [];
            _loc_7 = 0;
            while (_loc_7 < param1.waitingPlayers.length)
            {
                
                _loc_6 = param1.waitingPlayers[_loc_7] as SPublicMiniPlayer;
                if (EntityUtil.toString(_loc_6.entityId) != EntityUtil.toString(cache.role.entityInfo.entityId))
                {
                    _loc_5.push({label:_loc_6.name, player:_loc_6, level:_loc_6.level});
                }
                _loc_7++;
            }
            _loc_5.sortOn("level", Array.DESCENDING);
            this._copyGroupModule.updateNearByList(_loc_3, _loc_5);
            
        }

        private function doEnterCopy(param1:int) : void
        {
            var onAlertHandler:Function;
            var code:* = param1;
            onAlertHandler = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    GameProxy.groupProxy.createGroup(false, false);
                }
                
            }
            ;
            var copy:* = CopyConfig.instance.getInfoByCode(code);
            if (copy.singleMode == 1)
            {
                GameProxy.copy.enterCopyEx_async(code);
            }
            else if (!cache.group.isInGroup)
            {
                Alert.show("    单人不能进入组队副本，你确定要\n创建队伍吗？", "提示", Alert.OK | Alert.CANCEL, null, onAlertHandler);
            }
            else if (cache.group.isCaptain)
            {
                Alert.show("    你确定要开启并进入" + copy.name + "\n副本（组队）吗？", "提示", Alert.OK | Alert.CANCEL, null, function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    GameProxy.copy.enterCopyEx_async(code);
                }
                
            }
            );
            }
            else
            {
                GameProxy.copy.enterCopyEx_async(code);
            }
            
        }

        private function onAlertClickHandler(param1:int) : void
        {
            if (param1 == Alert.OK)
            {
                this.enterCopyHell();
            }
            
        }

        private function enterCopyHell() : void
        {
            GameProxy.copy.enterHell_async(cache.copy.copyInfo.code);
            this.onCopyNumInfoChange();
            this.updateMinimizeInfo();
            
        }

        private function updateRoomSettingWin(event:DataEvent) : void
        {
            var _loc_2:SGroup = null;
            if (!this._roomSetData)
            {
                this._roomSetData = new RoomSetData();
                _loc_2 = cache.copy.groupInfo;
                this._roomSetData.strRoomName = _loc_2.name;
                this._roomSetData.iLevelNeed = _loc_2.level;
                this._roomSetData.iPowerNeed = _loc_2.warfare;
                this._roomSetData.isFightOtherCanIn = _loc_2.joinInFighting;
                this._roomSetData.strPassword = _loc_2.pwd;
                this._roomSetData.career = _loc_2.career;
            }
            this._copyGroup.setRoomDefaultValues(this._roomSetData.strRoomName, this._roomSetData.iLevelNeed, this._roomSetData.iPowerNeed, this._roomSetData.career, this._roomSetData.isFightOtherCanIn, this._roomSetData.strPassword);
            
        }

        private function doCaptainViewGroup(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SGroupInvite;
            this.playerListWin.setGroupInfo(cache.copy.groupInfo, cache.copy.players);
            this.playerListWin.show();
            
        }

        private function doAgreeApply(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SGroupInvite;
            GameProxy.copy.agree_async(EGroupMsgType.EGroupMsgTypeApply, _loc_2.player.entityId, _loc_2.certId);
            cache.copy.removeFromApplyList(_loc_2);
            this.onApply();
            
        }

        private function doRejectApply(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SGroupInvite;
            GameProxy.copy.reject_async(EGroupMsgType.EGroupMsgTypeApply, _loc_2.player.entityId, _loc_2.certId);
            cache.copy.removeFromApplyList(_loc_2);
            this.onApply();
            
        }

        private function doAgreeInvite(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SGroupInviteEx;
            this.hintIcon.hide();
            GameProxy.copy.agree_async(EGroupMsgType.EGroupMsgTypeInvite, _loc_2.groupInfo.captainId, _loc_2.certId);
            cache.copy.removeFromInviteList(_loc_2);
            this.onInvite();
            
        }

        private function doRejectInvite(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SGroupInviteEx;
            this.hintIcon.hide();
            GameProxy.copy.reject_async(EGroupMsgType.EGroupMsgTypeInvite, _loc_2.groupInfo.captainId, _loc_2.certId);
            cache.copy.removeFromInviteList(_loc_2);
            this.onInvite();
            
        }

        private function doRefreshRoomList(event:DataEvent) : void
        {
            GameProxy.copy.findGroup_async(event.data["showFight"], event.data["fromIndex"]);
            
        }

        private function doViewGroup(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SGroup;
            cache.copy.viewGroupInfo = _loc_2;
            GameProxy.copy.viewGroup_async(_loc_2.groupId);
            
        }

        private function doJoin(event:DataEvent) : void
        {
            var _loc_2:* = event.data["groupData"] as SGroup;
            GameProxy.copy.joinGroup_async(_loc_2.groupId, event.data["pwd"], _loc_2.fighting);
            
        }

        private function doCreateGroup(event:DataEvent) : void
        {
            GameProxy.copy.createGroup_async(cache.role.entityInfo.name, "", 1, 0, 15, true);
            this._copyGroup.setRoomDefaultValues(cache.role.entityInfo.name, 1, 0, 15, true, "");
            this._roomSetData = new RoomSetData();
            this._roomSetData.strRoomName = cache.role.entityInfo.name;
            this._roomSetData.iLevelNeed = 1;
            this._roomSetData.iPowerNeed = 0;
            this._roomSetData.isFightOtherCanIn = true;
            this._roomSetData.strPassword = "";
            this._roomSetData.career = 15;
            
        }

        private function doOpenInviteWin(event:DataEvent) : void
        {
            var _loc_2:* = cache.copy.inviteList[0] as SGroupInviteEx;
            this.playerListWin.inviteInfo = _loc_2;
            this.playerListWin.show();
            
        }

        private function doLeave(event:DataEvent) : void
        {
            if (!cache.copy.isInGroup)
            {
                cache.copy.viewGroupInfo = null;
                cache.copy.groupInfo = null;
                cache.copy.players = [];
                this._copyGroup.updateGroupInfo(null);
            }
            else if (cache.copy.isFighting && cache.copy.isInGroup)
            {
                Alert.show("战斗中离开队伍，将会被强制\r传送出副本，是否继续？", null, Alert.YES | Alert.NO, null, this.onLeaveComfirm);
            }
            else
            {
                GameProxy.copy.leftGroup_async();
            }
            
        }

        private function doLeaveWithoutComfirm(event:DataEvent) : void
        {
            GameProxy.copy.leftGroup_async();
            
        }

        private function doKickOut(event:DataEvent) : void
        {
            var id:SEntityId;
            var e:* = event;
            id = e.data as SEntityId;
            if (cache.copy.groupInfo.fighting)
            {
                var alertResult:* = function (param1:int) : void
            {
                if (param1 == Alert.YES)
                {
                    GameProxy.copy.kickOutGroup_async(id);
                }
                
            }
            ;
                Alert.show("战斗中踢出队员，队员将会被强制离开副本，确认继续？", null, Alert.YES | Alert.NO, null, alertResult);
            }
            else
            {
                GameProxy.copy.kickOutGroup_async(id);
            }
            
        }

        private function doOpenCopy(event:DataEvent) : void
        {
            GameProxy.copy.enterCopy_async();
            this.stopOpenRoomHint();
            
        }

        private function updateCopyList() : void
        {
            var _loc_5:Array = null;
            var _loc_6:TCopy = null;
            var _loc_7:String = null;
            var _loc_8:int = 0;
            var _loc_1:* = CopyConfig.instance.getAllInfo();
            var _loc_2:* = new Dictionary();
            var _loc_3:int = 0;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_6 = _loc_1[_loc_3] as TCopy;
                if (_loc_6.showInHell == 1)
                {
                    if (_loc_2[_loc_6.name])
                    {
                        (_loc_2[_loc_6.name] as Array).push(_loc_6);
                    }
                    else
                    {
                        _loc_2[_loc_6.name] = new Array(_loc_6);
                    }
                }
                _loc_3++;
            }
            var _loc_4:Array = [];
            for each (_loc_5 in _loc_2)
            {
                
                _loc_7 = (_loc_5[0] as TCopy).name;
                _loc_8 = 0;
                while (_loc_8 < _loc_5.length)
                {
                    
                    _loc_4.push(new CopyListItem("", _loc_7, (_loc_5[_loc_8] as TCopy).enterMinLevel, _loc_5[_loc_8] as TCopy));
                    _loc_8++;
                }
            }
            _loc_4.sortOn(["enterMinLevel", "code"], Array.NUMERIC);
            this._entrance.copyListData = _loc_4;
            
        }

        private function FindPlayerHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data["name"];
            var _loc_3:* = int(event.data["level"]);
            var _loc_4:* = event.data["type"] as ECopyOrderType;
            var _loc_5:* = int(event.data["warfare"]);
            var _loc_6:* = int(event.data["career"]);
            var _loc_7:* = int(event.data["startIndex"]);
            if (cache.copy.isInHell)
            {
                GameProxy.copy.findPlayer_async(_loc_2, _loc_3, _loc_5, _loc_6, _loc_4, _loc_7);
            }
            
        }

        private function InvitePlayerHandler(event:DataEvent) : void
        {
            GameProxy.copy.invite_async(event.data as SEntityId);
            
        }

        private function updateCopyPlayers(param1:SCopyPlayerRet) : void
        {
            var _loc_7:SPublicMiniPlayer = null;
            var _loc_2:* = cache.copy.groupInfo && EntityUtil.toString(cache.copy.groupInfo.captainId) == EntityUtil.toString(cache.role.entityInfo.entityId);
            var _loc_3:Boolean = false;
            var _loc_4:* = param1.players.length;
            var _loc_5:Array = [];
            var _loc_6:int = 0;
            while (_loc_6 < _loc_4)
            {
                
                _loc_7 = param1.players[_loc_6] as SPublicMiniPlayer;
                _loc_5.push({isCaption:_loc_2, isInvited:_loc_3, data:_loc_7});
                _loc_6++;
            }
            this._copyGroup.updatePlayerList(_loc_5, param1.totalCount);
            
        }

        private function updateInviteData() : void
        {
            
        }

        private function onConfirmPanelButtonClick(event:Event) : void
        {
            switch(event.type)
            {
                case CopyConfirmPanel.MINIMIZE:
                {
                    break;
                }
                case CopyConfirmPanel.CANCEL:
                case CopyConfirmPanel.OK:
                {
                    this.hintIcon.hide();
                    break;
                }
                default:
                {
                    break;
                }
            }
            
        }

    }
}
